package com.u.social.multimedia.mq;

import com.alibaba.fastjson.JSON;
import com.u.social.multimedia.model.VideoMeta;
import com.u.social.multimedia.service.IVideoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: u-social
 * @description: 短剧MQ消费端数据访问层
 * @author: Alex Wu
 * @createDate: 2025-03-14 14:19
 **/

@Slf4j
@Service
@RocketMQMessageListener(topic = "short-video-topic", consumerGroup = "short-video-topic",
        maxReconsumeTimes = 3)  // 配置死信队列最好配置最大消费次数，否则按照16次计算
public class ShortVideoConsumer implements RocketMQListener<String> {


    @Autowired
    private IVideoService videoService;

    @Override
    public void onMessage(String message) {
        log.info("消费短剧消息：{}", message);
        VideoMeta videoMeta = JSON.parseObject(message, VideoMeta.class);

        // 应该需要下载到本地，然后进行切割，最后上传

        try {
            // 下载到本地
            // download
            // 切割
            String id = videoService.processAndUploadVideo(videoMeta);
            // 上传到hdfs
            // uploadToHdfs
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
